<template>
  <div class="editAttribute">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="属性分类" :required="true">
        <el-select v-model="AttrInfo.attribute_category_id">
          <el-option
            :label="item.name"
            v-for="(item, index) in categoryLists"
            :key="index"
            :value="item.id"
          ></el-option>

          <!-- <el-option label="区域二" value="beijing"></el-option> -->
        </el-select>
      </el-form-item>

      <el-form-item label="属性名称" :required="true">
        <el-input v-model="AttrInfo.name"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onPreserve(AttrInfo)">保存</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>

<script>
import { getCategoryLists, getAttrInfo,addAttrbute} from "../../request/httpApi";
export default {
 
  data() {
    return {
      form: {
        name: "",
        region: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      //信息
      AttrInfo: {},
      //Attribute.vue
      categoryLists: [],
    };
  },
  created() {
    //发送分类请求
    getCategoryLists().then((res) => {
      console.log(res);
      if (res.errno == 0) {
        this.categoryLists = res.data;
      }
    });
    //信息
    getAttrInfo({ id: this.$route.params.aid }).then((res) => {
      console.log(res);
      if (res.errno == 0) {
        this.AttrInfo = res.data;
      }
    });
  },
  methods: {
    onPreserve(val) {
      console.log(val);
      //   console.log(this.$route.params.aid);
      addAttrbute({
        attribute_category_id: val.attribute_category_id,
        id: val.id,
        input_type: val.input_type,
        is_new: false,
        is_show: false,
        name: val.name,
        sort_order: val.sort_order,
        values: val.values,
      }).then((res) => {
        //   console.log(res);
        if(res.errno==0){
        //  this.$router.push('attribute')
      this.$router.push("/attribute");

        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.editAttribute {
  background-color: #fff;
  padding-top: 10px;
  padding-left: 15px;
  padding-bottom: 20px;
}
/deep/ .el-input__inner {
  width: 200px;
}
</style>